//
//  GroupInfoHeaderView.m
//  Findif
//
//  Created by Mac on 2019/2/22.
//  Copyright © 2019年 Cicel Chen. All rights reserved.
//

#import "GroupInfoHeaderView.h"

@interface GroupInfoHeaderView ()

@property (nonatomic, weak)UIImageView * topImageView;
@property (nonatomic, weak)UIButton * backButton;
@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, weak)UILabel * nameLabel;
@property (nonatomic, weak)UILabel * numberLabel;
@property (nonatomic, weak)UILabel * IDLabel;
@property (nonatomic, weak)UIImageView * tView;


@end

@implementation GroupInfoHeaderView


- (void)setDict:(NSDictionary *)dict{
    
    _dict = dict;
    
    NSString * iconStr = [NSString stringWithFormat:@"%@%@",BASEURLSTR,dict[@"group_img"]];
    NSURL * iconUrl = [NSURL URLWithString:iconStr];
    [self.topImageView sd_setImageWithURL:iconUrl];
    
    self.nameLabel.text = dict[@"group_name"];
    self.numberLabel.text = [NSString stringWithFormat:@"%@",dict[@"group_jg_gid"]];
    
    NSArray *array = [dict[@"group_category_name"] componentsSeparatedByString:@","];
    
    CGFloat x = 15 * SCREENH6;
    CGFloat y = 120 * SCREENH6 + topHeight;
    CGFloat width = 40 * SCREENH6;
    CGFloat height = 20 * SCREENH6;
    CGFloat space = 5 * SCREENH6;
    for (int i = 0; i < array.count; i++) {
        
        UIButton * button = [[UIButton alloc] initWithFrame:CGRectMake(i * (width + space) + x, y, width, height)];
        
        NSString * title = [NSString stringWithFormat:@" %@ ",array[i]];
        [button setTitle:title forState:UIControlStateNormal];
        [button setTitleColor:ZRWhiteColor forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
        button.layer.cornerRadius = 10 * SCREENH6;
        button.layer.masksToBounds = YES;
        if ([title isEqualToString:@" 吃喝 "]) {
            
            [button setBackgroundColor:ColorWithRGB(0xEB7664)];
        }else if ([title isEqualToString:@" 玩乐 "]){
            
            [button setBackgroundColor:ColorWithRGB(0xAD77E9)];
        }else if ([title isEqualToString:@" 运动 "]){
            
            [button setBackgroundColor:ColorWithRGB(0x72D9AA)];
        }else if ([title isEqualToString:@" 旅行 "]){
            
            [button setBackgroundColor:ColorWithRGB(0x6AA3F1)];
        }
        
        [self.topImageView addSubview:button];
    }
}

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    
//    self.userInteractionEnabled = YES;
    
    UIImageView * topImageView = [[UIImageView alloc] init];
    
//    topImageView.backgroundColor = [UIColor grayColor];
    topImageView.userInteractionEnabled = YES;
    
    self.topImageView = topImageView;
    
    [self addSubview:self.topImageView];
    
    UIImageView * tView = [[UIImageView alloc] init];
    
    tView.image = [UIImage imageNamed:@"图片处理蒙板"];
    
    self.tView = tView;
    
    [self.topImageView addSubview:self.tView];
    
    
    UIButton * backButton = [UIButton new];
    
    [backButton setImage:[UIImage imageNamed:@"社团详情back"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(clickBackButton) forControlEvents:UIControlEventTouchUpInside];
    
    self.backButton = backButton;
    
    [self.topImageView addSubview:self.backButton];
    
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.textColor = ZRWhiteColor;
    titleLabel.text = @"社团资料";
    titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.hidden = YES;
    
    self.titleLabel = titleLabel;
    
    [self.topImageView addSubview:self.titleLabel];
    
    
    UILabel * nameLabel = [UILabel new];
    
    nameLabel.textColor = ZRWhiteColor;
    nameLabel.text = @"社团名";
    nameLabel.font = [UIFont systemFontOfSize:18 * SCREENH6];
//    nameLabel.textAlignment = NSTextAlignmentCenter;
    
    self.nameLabel = nameLabel;
    
    [self.topImageView addSubview:self.nameLabel];
    
    UILabel * IDLabel = [UILabel new];
    
    IDLabel.textColor = ZRWhiteColor;
    IDLabel.text = @"社团ID";
    IDLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    IDLabel.textAlignment = NSTextAlignmentCenter;
    
    self.IDLabel = IDLabel;
    
    [self.topImageView addSubview:self.IDLabel];
    
    
    UILabel * numberLabel = [UILabel new];
    
    numberLabel.textColor = ZRWhiteColor;
    numberLabel.text = @"----";
    numberLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    numberLabel.textAlignment = NSTextAlignmentRight;
    
    self.numberLabel = numberLabel;
    
    [self.topImageView addSubview:self.numberLabel];
}


- (void)layoutSubviews{
    
    [self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.bottom.mas_equalTo(self);
    }];
    
    [self.tView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.mas_equalTo(self.topImageView);
        make.height.mas_equalTo(70 * SCREENH6);
    }];
    
    [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.topImageView).offset(5 * SCREENH6);
        make.top.mas_equalTo(self.topImageView).offset(kStatusBarHeight);
        make.width.mas_equalTo(40 * SCREENH6);
        make.height.mas_equalTo(30 * SCREENH6);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.centerY.mas_equalTo(self.backButton);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.backButton.mas_bottom).offset(105 * SCREENH6);
        make.leading.mas_equalTo(self.topImageView).offset(15 * SCREENH6);
    }];
    
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.topImageView).offset(-30 * SCREENH6);
        make.top.mas_equalTo(self.topImageView).mas_equalTo(120 * SCREENH6 + topHeight);
    }];
    
    [self.IDLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.numberLabel);
        make.bottom.mas_equalTo(self.numberLabel.mas_top).offset(-5 * SCREENH6);
    }];
}


- (void)clickBackButton{
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickBackButton)])
    {
        
        [self.delegate clickBackButton];
    }
}




@end
